package factory;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.ResourceBundle;

public class ServiceFactory {
    private static HashMap<String ,Object> map = new HashMap<>();
    static {
        ResourceBundle bundle = ResourceBundle.getBundle("service");
        Enumeration<String> keys = bundle.getKeys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            String className = bundle.getString(key);
            System.out.println(key+":"+className);
            try {
                Class<?> aClass = Class.forName(className);
                Object o = aClass.newInstance();
                map.put(key,o);
                System.out.println(map);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
    //从容器中获取指定对象
    public static Object getBean(String key){
        return map.get(key);
    }
}
